package cn.ming.leo.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.listener.ChannelTopic;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;

@Configuration
public class RedisConfig1 {

	@Autowired
	private JedisConnectionFactory jedisConnectionFactory;

	@Bean
	public ConsumerRedisListener consumerRedis() {
		return new ConsumerRedisListener();
	}

	@Bean
	public ChannelTopic topic() {
		return new ChannelTopic("leo");
	}

	@Bean
	public RedisMessageListenerContainer redisMessageListenerContainer() {

		RedisMessageListenerContainer container = new RedisMessageListenerContainer();
		container.setConnectionFactory(jedisConnectionFactory);

		container.addMessageListener(consumerRedis(), topic());
		return container;

	}

}
